package com.ruoyi.user_list.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.user_list.domain.MobileUser;
import com.ruoyi.user_list.service.IMobileUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 移动端用户管理Controller
 * 
 * @author leo
 * @date 2024-10-07
 */
@RestController
@RequestMapping("/user_list/user_list")
public class MobileUserController extends BaseController
{
    @Autowired
    private IMobileUserService mobileUserService;

    /**
     * 查询移动端用户管理列表
     */
    @PreAuthorize("@ss.hasPermi('user_list:user_list:list')")
    @GetMapping("/list")
    public TableDataInfo list(MobileUser mobileUser)
    {
        startPage();
        List<MobileUser> list = mobileUserService.selectMobileUserList(mobileUser);
        return getDataTable(list);
    }

    /**
     * 导出移动端用户管理列表
     */
    @PreAuthorize("@ss.hasPermi('user_list:user_list:export')")
    @Log(title = "移动端用户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MobileUser mobileUser)
    {
        List<MobileUser> list = mobileUserService.selectMobileUserList(mobileUser);
        ExcelUtil<MobileUser> util = new ExcelUtil<MobileUser>(MobileUser.class);
        util.exportExcel(response, list, "移动端用户管理数据");
    }

    /**
     * 获取移动端用户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('user_list:user_list:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Integer userId)
    {
        return success(mobileUserService.selectMobileUserByUserId(userId));
    }

    /**
     * 新增移动端用户管理
     */
    @PreAuthorize("@ss.hasPermi('user_list:user_list:add')")
    @Log(title = "移动端用户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MobileUser mobileUser)
    {
        return toAjax(mobileUserService.insertMobileUser(mobileUser));
    }

    /**
     * 修改移动端用户管理
     */
    @PreAuthorize("@ss.hasPermi('user_list:user_list:edit')")
    @Log(title = "移动端用户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MobileUser mobileUser)
    {
        return toAjax(mobileUserService.updateMobileUser(mobileUser));
    }

    /**
     * 删除移动端用户管理
     */
    @PreAuthorize("@ss.hasPermi('user_list:user_list:remove')")
    @Log(title = "移动端用户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Integer[] userIds)
    {
        return toAjax(mobileUserService.deleteMobileUserByUserIds(userIds));
    }
    @PreAuthorize("@ss.hasPermi('user_list:user_list:edit')")
    @Log(title = "重置移动端用户密码", businessType = BusinessType.UPDATE)
    @PostMapping("resestPwd/{id}")
    public AjaxResult resetPwd(@PathVariable Integer id){
        MobileUser mobileUser = new MobileUser();
        mobileUser.setUserId(id); //设置id
        mobileUser.setPassword("123456");//设置加密后的密码
        return toAjax(mobileUserService.updateMobileUser(mobileUser));
    }
}
